package com.phuonhoang.utils;

import com.phuonghoang.model.RssItem;
import java.net.URL;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class RssParser {
	public List<RssItem>getNewList(String link){
		try{
		URL url = new URL(link);
		SAXParserFactory factory = SAXParserFactory.newInstance();
		SAXParser parser = factory.newSAXParser();
		
		XMLReader reader =  parser.getXMLReader();
		RssHandler rssHandler = new RssHandler();
		
		reader.setContentHandler(rssHandler);
		InputSource source = new InputSource(url.openStream());	
		
		reader.parse(source);
		return rssHandler.getItemList();
		}
		catch(Exception e){
			e.printStackTrace();
			return null;
		}
		
	}
}
